package org.csu.mypetstore.web.servlets;

import org.csu.mypetstore.domain.Account;
import org.csu.mypetstore.service.LogService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "UserAccountServlet", value = "/UserAccountServlet")
public class UserAccountServlet extends HttpServlet {
    private final static String USER_ACCOUNT = "/WEB-INF/jsp/account/MyAccount.jsp";
    private LogService logService = new LogService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        Account account = (Account)session.getAttribute("account");
        if(account!=null){
            String logInfo = logService.logInfo(" ")  + " 用户查看我的账号";
            logService.insertLogInfo(account.getUsername(), logInfo);
        }

        request.getRequestDispatcher(USER_ACCOUNT).forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
